package com.xcity.game.activity2.platform;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.account.AccountChannel;
import com.xcity.game.mail.MailAttach;

/**
 * 各平台/渠道礼包<br/>
 * @author yang.li
 *
 */
public class PlatformGift {

	public byte type; // 礼包类型
	@JSONField(serialize = false)
	public AccountChannel channel; // 礼包所属渠道
	public int id; // 礼包id
	public MailAttach content; // 礼包内容

	// 礼包类型（关注礼包、登录礼包、分享礼包）
	public static final byte TYPE_FOLLOW = 1, TYPE_LOGIN = 2, TYPE_SHARE = 3;
	// 不能领取、可领取、已领取
	public static final byte STATE_CAN_NOT_RECEIVE = -1, STATE_CAN_RECEIVE = 0, STATE_RECEIVED = 1;
	// 领取成功（临时状态）
	public static final byte STATE_RECEIVE_SUCC = 2;
	
	public PlatformGift() {}
	
	public PlatformGift(byte type, AccountChannel channel, int id, MailAttach content) {
		this.type = type;
		this.channel = channel;
		this.id = id;
		this.content = content;
	}
	
	public void addGold(int gold) {
		requireNonNull();
		content.setGold(content.getGold() + gold);
	}
	
	public void addStone(int stone) {
		requireNonNull();
		content.setStone(content.getStone() + stone);
	}
	
	public void addItem(int id, int count) {
		requireNonNull();
		content.addItem(id, count);
	}
	
	private void requireNonNull() {
		if (content == null) {
			content = new MailAttach();
		}
	}
	
}
